import Vue from 'vue'
import bus from '../bus'
import Router from 'vue-router'
import Login from '@/components/Login'
import Index from '@/components/Index'
import SysUser from '@/components/sys/user/List'
import SysGroup from '@/components/sys/group/List'
import SysLog from '@/components/sys/log/List'

Vue.use(Router);

const router = new Router({
  routes: [
    {path: '/login', component: Login},
    {path: '/', component: Index, children: [
        {path: '/sys/user', component: SysUser, meta: {title: '管理员列表'}},
        {path: '/sys/group', component: SysGroup, meta: {title: '用户组列表'}},
        {path: '/sys/log', component: SysLog, meta: {title: '操作日志'}}
      ]},
  ]
});

router.afterEach((to, from) => {
  if (to.meta && to.meta.title) {
    bus.$emit('title', to.meta.title)
  }
});


export default router;